#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

#include "forward_list.h"

namespace UnitTestForwardList
{
	TEST_CLASS(UnitTestForwardList)
	{
	public:

		TEST_METHOD(TestForwardList_is_empty)
		{
			forward_list<int> fli;


			Assert::AreEqual(true, fli.is_empty());
		}

		TEST_METHOD(TestForwardList_push_front_and_front)
		{
			forward_list<int> fli;
			int x = 10;
			int y = 20;
			int z = 30;
			fli.push_front(x);
			Assert::AreEqual(10, fli.front());
			fli.push_front(y);
			Assert::AreEqual(20, fli.front());
			fli.push_front(z);
			Assert::AreEqual(30, fli.front());
		}

		TEST_METHOD(TestForwardList_Clear_List)
		{
			forward_list<int> fli;
			int x = 10;
			int y = 20;
			int z = 30;
			fli.push_front(x);
			fli.push_front(y);
			fli.push_front(z);
			fli.clear();
			Assert::AreEqual(true, fli.is_empty());
		}

		TEST_METHOD(TestForwardList_iterator_begin_end)
		{
			forward_list<int> fli;
			int x = 10;
			int y = 20;
			int z = 30;
			fli.push_front(x);
			fli.push_front(y);
			fli.push_front(z);
			fli.iteratorBegin();
			Assert::AreEqual(30, fli.front());
			fli.pop_front();
			fli.pop_front();
			fli.iteratorEnd();
			Assert::AreEqual(10, fli.front());

		}

		TEST_METHOD(TestForwardList_pop_front)
		{
			forward_list<int> fli;
			int x = 10;
			int y = 20;
			int z = 30;
			fli.push_front(x);
			fli.push_front(y);
			fli.push_front(z);
			fli.pop_front();
			Assert::AreEqual(20, fli.front());
			fli.pop_front();
			Assert::AreEqual(10, fli.front());
		}

		TEST_METHOD(TestForwardList_size)
		{
			forward_list<int> fli;
			int x = 10;
			int y = 20;
			int z = 30;
			fli.push_front(x);
			fli.push_front(y);
			fli.push_front(z);
			Assert::AreEqual(3, fli.forwardListSize());
			fli.pop_front();
			Assert::AreEqual(2, fli.forwardListSize());
		}
		TEST_METHOD(TestForwardList_Insert_After)
		{
			forward_list<int> fli;
			int x = 10;
			int y = 20;
			int z = 30;
			fli.push_front(x);
			fli.push_front(y);
			fli.insertAfter(z, 1);
			fli.pop_front();
			fli.pop_front();
			Assert::AreEqual(30, fli.front());
		}
		TEST_METHOD(TestForwardList_Erase_After)
		{
			forward_list<int> fli;
			int x = 10;
			int y = 20;
			int z = 30;
			fli.push_front(x);
			fli.push_front(y);
			fli.push_front(z);
			fli.eraseAfter(1);
			fli.pop_front();
			fli.pop_front();
			Assert::AreEqual(true, fli.is_empty());
		}
		TEST_METHOD(TestForwardList_Swap)
		{
			forward_list<int> fli1;
			forward_list<int> fli2;
			int x = 10;
			int y = 20;
			fli1.push_front(x);
			fli1.push_front(y);
			fli2.push_front(y);
			fli2.push_front(x);
			Assert::AreEqual(20, fli1.front());
			Assert::AreEqual(10, fli2.front());
			fli1.swap(fli2);
			Assert::AreEqual(10, fli1.front());
			Assert::AreEqual(20, fli2.front());
		}
	};
}